//index.js
var t = getApp(),
  c = t.requirejs("api/index"),
  a = t.requirejs("core"); 
Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    circular: true,
    list:[]
  },
  onLoad: function () {
    var that = this;
    if (wx.getExtConfig) {
      wx.getExtConfig({
        success: function (res) {
          console.log(res)
          if (res.errMsg == "getExtConfig: ok") {
            getApp().globalData.appid = res.extConfig.app_key ? res.extConfig.app_key : '';
            getApp().globalData.app_name = res.extConfig.app_name ? res.extConfig.app_name : getApp().globalData.app_name;
            that.getinfo();
            that.newslist()
          } else {
            a.alert('app.js(13):' + res.errMsg)
          }
        }
      })
    }
  },
  onShow: function(){
   
   
  },
   /**
    * 获取轮播图、广告
    */
  getinfo: function(){
    var t = this;
    var width = 372;
    width = wx.getSystemInfoSync().windowWidth;
    t.setData({
      loading: true
    }),
      a.get("index/index", {}, function (i) {

        if (i.code == 0) {
          var d = i.info.advert_position_list;
          //计算广告高度
          d[2].advert_position.forEach(function (k) {
            k.high = width * k.height / k.width
          })
          t.setData({
            loading: false,
            show: true,
          })

          t.setData({
            info: d
          })
        } else {
          a.alert(i.msg)
        }
      })
  },
  onPullDownRefresh: function () {
    this.setData({
      list: []
    })
    this.getinfo()
    this.newslist()
    wx.stopPullDownRefresh();
  },
  /**
    * 获取首页推荐文章
    */
  newslist: function () {
    var that = this;
    c.article_list('index', 1,'', that, function (t) {
      that.setData(t)
    })
  },
  onShareAppMessage: function (res) {
    a.onShareAppMessage()
  }

}) 